

package com.hazelcast.internal.nio.ascii;

import com.hazelcast.internal.ascii.CommandParser;
import com.hazelcast.internal.ascii.memcache.*;
import com.hazelcast.internal.server.ServerConnection;

import java.util.HashMap;
import java.util.Map;

import static com.hazelcast.internal.ascii.TextCommandConstants.TextCommandType.*;

public class MemcacheTextDecoder extends TextDecoder {

    public static final TextParsers TEXT_PARSERS;

    static {
        Map<String, CommandParser> parsers = new HashMap<>();
        parsers.put("get", new GetCommandParser());
        parsers.put("gets", new GetCommandParser());
        parsers.put("set", new SetCommandParser(SET));
        parsers.put("add", new SetCommandParser(ADD));
        parsers.put("replace", new SetCommandParser(REPLACE));
        parsers.put("append", new SetCommandParser(APPEND));
        parsers.put("prepend", new SetCommandParser(PREPEND));
        parsers.put("touch", new TouchCommandParser(TOUCH));
        parsers.put("incr", new IncrementCommandParser(INCREMENT));
        parsers.put("decr", new IncrementCommandParser(DECREMENT));
        parsers.put("delete", new DeleteCommandParser());
        parsers.put("quit", new SimpleCommandParser(QUIT));
        parsers.put("stats", new SimpleCommandParser(STATS));
        parsers.put("version", new SimpleCommandParser(VERSION));
        TEXT_PARSERS = new TextParsers(parsers);
    }

    public MemcacheTextDecoder(ServerConnection connection, TextEncoder encoder, boolean rootDecoder) {
        super(connection, encoder, AllowingTextProtocolFilter.INSTANCE, TEXT_PARSERS, rootDecoder);
    }
}
